package com.datechange.utils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.datechange.datatype.HolidayTypeEnum;

public class DateUtils {
	public Map<String, String> getBillGenerationDate(Date effectiveDate, int noOfBillingCycle, HolidayTypeEnum holiday) {
		Map<String, String> monthNumberNDateMap = new HashMap<String, String>();
		Calendar cal = Calendar.getInstance();
		DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
		for (int i = 1; i <= (noOfBillingCycle-2); i++) {
			cal.setTime(effectiveDate);
			// DDi
			cal.add(Calendar.MONTH, i);
			// DDi-20
			cal.add(Calendar.DAY_OF_MONTH, -20);
			if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
				if(HolidayTypeEnum.previousday.equals(holiday)){
					cal.add(Calendar.DAY_OF_MONTH, -2);
				} else if(HolidayTypeEnum.nextday.equals(holiday)){
					cal.add(Calendar.DAY_OF_MONTH, 1);
				}
			} else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {
				if(HolidayTypeEnum.previousday.equals(holiday)){
					cal.add(Calendar.DAY_OF_MONTH, -1);
				}else if(HolidayTypeEnum.nextday.equals(holiday)) {
					cal.add(Calendar.DAY_OF_MONTH, 2);
				}
			}
			monthNumberNDateMap.put(String.valueOf(i),
					df.format(cal.getTime()));
		}
		return monthNumberNDateMap;
	}
}
